package com.test.design.material.materialdesign;


import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

/**
 * author:harisucici on 2018/7/4 09:24
 * email:harisucici@gmail.com
 * name:
 * todo:
 */
public class MessageItemTouchCallback extends ItemTouchHelper.Callback {
    public ItemTouchHelperAdapterInterface getItemTouchHelperAdapterInterface() {
        return itemTouchHelperAdapterInterface;
    }

    private ItemTouchHelperAdapterInterface itemTouchHelperAdapterInterface;

    public MessageItemTouchCallback(ItemTouchHelperAdapterInterface itemTouchHelperAdapterInterface){
        this.itemTouchHelperAdapterInterface = itemTouchHelperAdapterInterface;
    }

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {

        int dragFlags = ItemTouchHelper.UP|ItemTouchHelper.DOWN;
        int swipeFlags = ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT;

        return makeMovementFlags(dragFlags,swipeFlags);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder srcHolder,  RecyclerView.ViewHolder destHolder) {
        itemTouchHelperAdapterInterface.onItemMove(srcHolder.getAdapterPosition(),destHolder.getAdapterPosition());
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
        itemTouchHelperAdapterInterface.onItemSwiped(viewHolder.getAdapterPosition());
    }

    //长按拖拽
    @Override
    public boolean isLongPressDragEnabled() {
        return false;
    }
}
